<!-- 订单管理 -->
<template>
  <div class="dashboard-container order-list customer-list-box">
    <div class="app-container">
      <!-- form表单 -->
      <el-card>
        <el-form
          ref="fromRef"
          label-width="110px"
          :inline="true"
          :model="orderFrom"
          class="demo-form-inline"
        >
          <!-- 订单编号 -->
          <el-col :span="8">
            <el-form-item
              label="订单编号"
              prop="orderId"
            >
              <el-input
                v-model="orderFrom.id"
                placeholder="请输入订单编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <!-- 订单状态 -->
          <el-col :span="8">
            <el-form-item
              label="订单状态"
              prop="status"
            >
              <el-select
                v-model="orderFrom.status"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in list"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 付款状态 -->
          <el-col :span="8">
            <el-form-item
              label="付款状态"
              prop="paymentStatus"
            >
              <el-select
                v-model="orderFrom.paymentStatus"
                placeholder="请选择"
              >
                <el-option
                  label="已付"
                  value="shanghai"
                ></el-option>
                <el-option
                  label="未付"
                  value="beijing"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 发件人姓名 -->
          <el-col :span="8">
            <el-form-item
              label="发件人姓名"
              prop="senderName"
            >
              <el-input
                v-model="orderFrom.senderName"
                placeholder="请输入发件人姓名"
              ></el-input>
            </el-form-item>
          </el-col>
          <!-- 发件人电话 -->
          <el-col :span="8">
            <el-form-item
              label="发件人电话"
              label-width="110px"
              prop="senderPhone"
            >
              <el-input
                v-model="orderFrom.senderPhone"
                placeholder="请输入发件人电话"
              ></el-input>
            </el-form-item>
          </el-col>
          <!-- 发件人地址 -->
          <el-col :span="8">
            <el-form-item
              label="发件人地址"
              label-width="90px"
            >
              <el-row
                style="width:300px"
                type="flex"
              >
                <!-- 发件人省 -->
                <el-select
                  v-model="orderFrom.senderProvince"
                  placeholder="请选择"
                  @change="change"
                >
                  <el-option
                    v-for="item in provinceList"
                    :key="item.areaId"
                    :label="item.areaName"
                    :value="item.areaId"
                  ></el-option>
                </el-select>
                <!-- 发件人城市 -->
                <el-select
                  v-model="orderFrom.senderCity"
                  placeholder="请选择"
                  @change="changecity"
                >
                  <el-option
                    v-for="item in cityList"
                    :key="item.areaId"
                    :label="item.areaName"
                    :value="item.areaId"
                  ></el-option>
                </el-select>
                <!-- 发件人区县 -->
                <el-select
                  v-model="orderFrom.senderCounty"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in countyList"
                    :key="item.areaId"
                    :label="item.areaName"
                    :value="item.areaId"
                  ></el-option>
                </el-select>
              </el-row>
            </el-form-item>
          </el-col>
          <!-- 收件人姓名 -->
          <el-col :span="8">
            <el-form-item
              label="收件人姓名"
              prop="receiverName"
            >
              <el-input
                v-model="orderFrom.receiverName"
                placeholder="请输入收件人姓名"
              ></el-input>
            </el-form-item>
          </el-col>
          <!-- 收件人电话 -->
          <el-col :span="8">
            <el-form-item
              label="收件人电话"
              prop="receiverPhone"
            >
              <el-input
                v-model="orderFrom.receiverPhone"
                placeholder="请输入收件人电话"
              ></el-input>
            </el-form-item>
          </el-col>
          <!-- 收件人地址 -->
          <el-col :span="8">
            <el-form-item
              label="收件人地址"
              label-width="90px"
            >
              <el-row
                style="width:300px"
                type="flex"
              >
                <el-select
                  v-model="orderFrom.receiverProvince"
                  placeholder="请选择"
                  @change="changeReceiver"
                >
                  <el-option
                    v-for="item in receiverList"
                    :key="item.areaId"
                    :label="item.areaName"
                    :value="item.areaId"
                  ></el-option>
                </el-select>
                <!-- 发件人城市 -->
                <el-select
                  v-model="orderFrom.receiverCity"
                  placeholder="请选择"
                  @change="changereceivercity"
                >
                  <el-option
                    v-for="item in receiverCityList"
                    :key="item.areaId"
                    :label="item.areaName"
                    :value="item.areaId"
                  ></el-option>
                </el-select>
                <!-- 发件人区县 -->
                <el-select
                  v-model="orderFrom.receiverCounty"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in receiverCountyList"
                    :key="item.areaId"
                    :label="item.areaName"
                    :value="item.areaId"
                  ></el-option>
                </el-select>
              </el-row>
            </el-form-item>
          </el-col>
          <el-button
            type="danger"
            @click="search"
          >搜索</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form>
      </el-card>
    </div>
    <div class="tableList">
      <el-card class="card">
        <!-- 表格 -->
        <el-table
          :data="tableData"
        >
          <!-- 序号 -->
          <el-table-column
            prop="date"
            label="序号"
            width="180"
            type="index"
          >
          </el-table-column>
          <!-- 订单编号 -->
          <el-table-column
            prop="memberId"
            label="订单编号"
            width="180"
          >
          </el-table-column>
          <!-- 运单编号 -->
          <el-table-column
            prop="transportOrder.id"
            label="运单编号"
          >
          </el-table-column>
          <!-- 下单时间 -->
          <el-table-column
            prop="createTime"
            label="下单时间"
          >
          </el-table-column>
          <!-- 订单状态 -->
          <el-table-column
            prop="status"
            label="订单状态"
          >
          </el-table-column>
          <!-- 发件人姓名 -->
          <el-table-column
            prop="senderName"
            label="发件人姓名"
          >
          </el-table-column>
          <!-- 发件人电话 -->
          <el-table-column
            prop="senderPhone"
            label="发件人电话"
          >
          </el-table-column>
          <!-- 发件人地址 -->
          <el-table-column
            prop="senderAddress"
            label="发件人地址"
          >
          </el-table-column>
          <!-- 收件人姓名 -->
          <el-table-column
            prop="receiverName"
            label="收件人姓名"
          >
          </el-table-column>
          <!-- 收件人电话 -->
          <el-table-column
            prop="receiverPhone"
            label="收件人电话"
          >
          </el-table-column>
          <!-- 收件人地址 -->
          <el-table-column
            prop="receiverAddress"
            label="收件人地址"
          >
          </el-table-column>
          <!-- 取件类型 -->
          <el-table-column
            prop="pickupType"
            label="取件类型"
          >
            <!-- 使用默认插槽 解构里面的row -->
            <template #default="{row}">
              <!-- 拿出row里面的取件类型 做三元判断 -->
              <span>{{ row.pickupType?'网点自寄':'上门取件' }}</span>
            </template>
          </el-table-column>
          <!-- 付费类型 -->
          <el-table-column
            prop="paymentMethod"
            label="付费类型"
            width="160px"
          >
            <!-- 使用默认插槽 解构里面的row -->
            <template #default="{row}">
              <!-- 拿出row里面的付费类型 做三元判断 -->
              <span>{{ row.paymentMethod?'预结':'到付' }}</span>
            </template>
          </el-table-column>
          <!-- 付费状态 -->
          <el-table-column
            prop="paymentStatus"
            label="付费状态"
          >
            <!-- 使用默认插槽 解构里面的row -->
            <template #default="{row}">
              <!-- 拿出row里面的付费状态 做三元判断 -->
              <span>{{ row.paymentMethod?'已付':'未付' }}</span>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            prop="address"
            label="操作"
          >
            <template v-slot="{ row }">
              <el-button
                type="text"
                @click="$router.push({
                  path: '/business/edit-order',
                  query:{id:row.id}
                })"
              >
                查看详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- <div v-show="getList===''">
          <img src="../../assets/icon-empty.png">
          <p>没找到</p>
        </div> -->
        <!-- 分页 -->
        <div class="curpage">
          <el-pagination
            :page="1"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          >
          </el-pagination>
        </div>

      </el-card>
    </div>
  </div>
</template>
<script>
// 引入获取列表api
import { orderList } from '@/api/order'
// 自定义引入省市区json文件
import getProvince from '@/api/city.json'
export default {
  data() {
    return {
      // 默认总条数为0
      total: 0,
      // form表单数据
      orderFrom: {
        page: 1,
        pageSize: 10,
        // 订单编号
        orderId: '',
        // 订单状态
        status: '',
        // 付款状态
        paymentStatus: '',
        // 发件人姓名
        senderName: '',
        // 发件人电话
        senderPhone: '',
        // 收件人姓名
        receiverName: '',
        // 收件人电话
        receiverPhone: '',
        // 发件人省份
        senderProvince: '',
        // 发件人城市
        senderCity: '',
        // 发件人区县
        senderCounty: '',
        // 收件人省份
        receiverProvince: '',
        // 收件人城市
        receiverCity: '',
        // 收件人区县
        receiverCounty: ''
      },
      // 表单校验规则
      // rules: {
      //   orderId: [
      //     { required: true, message: '订单编号不能为空', trigger: 'blur' },
      //     { pattern: /^(SL)\d{17}$/, message: '订单编号为19位', trigger: 'blur' }
      //   ],
      //   status: [
      //     { required: true, message: '请选择订单状态', trigger: 'blur' }
      //   ],
      //   paymentStatus: [
      //     { required: true, message: '请选择付款状态', trigger: 'blur' }
      //   ],
      //   senderName: [
      //     { required: true, message: '发件人姓名不能为空', trigger: 'blur' },
      //     { pattern: /^[\u4e00-\u9fa5]+$/, message: '请填写汉字', trigger: 'blur' }
      //   ],
      //   senderPhone: [
      //     { required: true, message: '发件人电话不能为空', trigger: 'blur' },
      //     { pattern: /^1[3-9]\d{0,9}$/, message: '手机号输入有误', trigger: 'blur' }
      //   ],
      //   receiverName: [
      //     { required: true, message: '收件人姓名不能为空', trigger: 'blur' },
      //     { pattern: /^[\u4e00-\u9fa5]+$/, message: '请填写汉字', trigger: 'blur' }
      //   ],
      //   receiverPhone: [
      //     { required: true, message: '收件人电话不能为空', trigger: 'blur' },
      //     { pattern: /^1[3-9]\d{0,9}$/, message: '手机号输入有误', trigger: 'blur' }
      //   ]
      // },
      // 订单状态
      list: [
        {
          id: 23000,
          name: '待取件'
        },
        {
          id: 23001,
          name: '已取件'
        },
        {
          id: 23005,
          name: '运输中'
        },
        {
          id: 23008,
          name: '派送中'
        },
        {
          id: 23009,
          name: '已签收'
        },
        {
          id: 23010,
          name: '拒收'
        },
        {
          id: 230011,
          name: '已取消'
        },
        {
          id: 0,
          name: '全部'
        }
      ],
      // 付费方式
      getMoney: [
        {
          id: 1,
          name: '已付'
        },
        {
          id: 2,
          name: '未付'
        }

      ],
      // 列表数据
      tableData: [],
      // 省列表
      provinceList: [],
      // 市列表
      cityList: [],
      // 区列表
      countyList: [],
      // 自定义value 获取省份id
      cityValue: 0,
      // 自定义value 获取市级id
      countyValue: 0,
      // 收件人省列表
      receiverList: [],
      // 市列表
      receiverCityList: [],
      // 区列表
      receiverCountyList: [],
      // 自定义value 获取省份id
      receiverCityValue: 0,
      // 自定义value 获取市级id
      receiverCountyValue: 0
    }
  },
  computed: {

  },
  // 初始化前就调用数据
  created() {
    // this.orderList()
    console.log(getProvince)
    // 省市区列表赋值发件人
    this.provinceList = getProvince
    // 省市区列表赋值收件人
    this.receiverList = getProvince
    // 调用列表数据
    this.getList()
  },
  methods: {
    // 声明一个方法用来获取
    async getList() {
      const res = await orderList(this.orderFrom)
      console.log(res.data)
      // 将拿到的数据赋值给声明存数据的空数组
      this.tableData = res.data.items
      // 将页码赋值给提前设置的默认页码
      this.orderFrom.page = res.data.page
      // 将总条数赋值 json类型 需要转换
      this.total = Number(res.data.counts)
    },
    // 重置表单
    resetForm() {
      this.$refs.fromRef.resetFields()
      this.orderFrom.senderProvince = ''
      this.orderFrom.senderCity = ''
      this.orderFrom.senderCounty = ''
      this.cityList = ''
      this.countyList = ''
      // 清空收件人省
      this.orderFrom.receiverProvince = ''
      // 清空收件人城市
      this.orderFrom.receiverCity = ''
      // 清空发件人区县
      this.orderFrom.receiverCounty = ''
      this.receiverCountyList = ''
      this.receiverCityList = ''
    },
    // 页数赋值 自带value
    handleSizeChange(value) {
      console.log(value)
      this.orderFrom.pageSize = value
      // 重新获取列表数据
      this.getList()
    },
    // 当前页赋值 自带value
    handleCurrentChange(value) {
      console.log(value)
      this.orderFrom.page = value
      // 重新获取列表数据
      this.getList()
    },
    // change事件获取省市区
    change(value) {
      // 清空发件人城市
      this.orderFrom.senderCity = ''
      // 清空发件人区县
      this.orderFrom.senderCounty = ''
      this.countyList = ''
      // console.log(value)
      this.cityValue = value
      this.provinceList.forEach(item => {
        console.log(item)
        console.log(this.cityValue)
        if (item.areaId === this.cityValue) {
          console.log(item.cities)
          this.cityList = item.cities
        }
      })
    },
    // 发件人区县
    changecity(value) {
      this.orderFrom.senderCounty = ''
      console.log(value)
      this.countyList = value
      this.cityList.forEach(item => {
        console.log(item)
        if (item.areaId === this.countyList) {
          this.countyList = item.counties
        }
      })
    },
    // 收件人省市
    changeReceiver(value) {
      // 清空收件人城市
      this.orderFrom.receiverCity = ''
      // 清空发件人区县
      this.orderFrom.receiverCounty = ''
      this.receiverCountyList = ''
      this.receiverCityValue = value
      this.receiverList.forEach(item => {
        if (item.areaId === this.receiverCityValue) {
          this.receiverCityList = item.cities
        }
      })
    },
    // 获取收件人区县
    changereceivercity(value) {
      this.orderFrom.receiverCounty = ''
      this.receiverCountyList = value
      this.receiverCityList.forEach(item => {
        if (item.areaId === this.receiverCountyList) {
          this.receiverCountyList = item.counties
        }
      })
    },
    // 搜索
    async search() {
      this.getList(this.orderFrom)
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.app-container{
  // width: 1281px;
  height: 260px;
  background-color: #fff;
  margin: 0 auto;
}
.card{
  // height: 1100px;
}
.tableList{
  // height: 1300px;
  // width: 1281px;
  margin: 0 auto;
  margin-top:20px
}
.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 40px;
}
// 下拉框
::v-deep .el-select {
  width: 100%;
}
.order-list::v-deep .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}
.curpage{
  height: 80px;
}
</style>
